﻿package src{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;

	import org.papervision3d.lights.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.primitives.*
	import org.papervision3d.materials.*;
    import org.papervision3d.materials.utils.*;
	import org.papervision3d.materials.shadematerials.*;
	import org.papervision3d.core.geom.*;
	import org.papervision3d.core.geom.renderables.*;

	public final class Box extends DisplayObject3D {
		private var config:Object = CB.config;
		public function Box():void {
			draw();
			CB.addEventListener(E.RESIZE,resizeHandler);
		}
		
		private function draw():void {
			var pl:PointLight3D = new PointLight3D();
			//pl.x =  0;
            pl.y = 1000;
			//pl.z =  0;
			//trace(pl.x + "|" + pl.y + "|" + pl.z);
			/*
			var mate:FlatShadeMaterial = new FlatShadeMaterial(pl, 0xcccccc, 0x333333, 0);
            var paper:PaperPlane = new PaperPlane(mate, 2);
            paper.material.doubleSided = true;
            addChild(paper);
			*/
			
			var sp1:Sprite = new Sprite();
            var sp2:Sprite = new Sprite();
            var sp3:Sprite = new Sprite();
            var sp4:Sprite = new Sprite();
            var sp5:Sprite = new Sprite();
            var sp6:Sprite = new Sprite();
			
			dsp(sp1, 0xff0000);
			dsp(sp2, 0xffff00);
			dsp(sp3, 0x00ff00);
			dsp(sp4, 0x00ffff);
			dsp(sp5, 0xff00ff);
			dsp(sp6, 0xcccccc);

			var mm1:MovieMaterial = new MovieMaterial(sp1, true, false, false);
            var mm2:MovieMaterial = new MovieMaterial(sp2, true, false, false);
            var mm3:MovieMaterial = new MovieMaterial(sp3, true, false, false);
            var mm4:MovieMaterial = new MovieMaterial(sp4, true, false, false);
            var mm5:MovieMaterial = new MovieMaterial(sp5, false, false, false);
            var mm6:MovieMaterial = new MovieMaterial(sp6, false, false, false);
            
			var ml:MaterialsList = new MaterialsList({front:mm1, back:mm2, right:mm3, left:mm4, top:mm5, bottom:mm6});
			
			var cube:Cube = new Cube(ml, config.width * 0.5, config.width * 0.5, config.height * 0.5, 6, 6, 6);
			addChild(cube);
		}
		
		private function dsp(sp:Sprite, c:uint):void {
			sp.graphics.beginFill(c);
			sp.graphics.drawRect(0, 0, 100, 100);
			sp.graphics.endFill();
		}
		//========================================================
		private function resizeHandler(e:E=null):void {

		}

	}
}